import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.StampedLock;

public class Main {

    private ReentrantLock reentrantLock;

    private ReentrantReadWriteLock reentrantReadWriteLock;

    private StampedLock stampedLock;

    public static void main(String[] args) {

        Trick trick = new Trick();

        new Thread(trick, "thread1").start();
        new Thread(trick, "thread2").start();
        new Thread(trick, "thread3").start();

    }

    static class Trick implements Runnable {

        private Integer num = 10;

        //        这个方法演示正常卖票线程执行
        @Override
        public void run() {
            while (true) {
                System.out.println(Thread.currentThread().getName() + "开始卖票,剩余票数:" + num);
                num--;
                if (num < 0) {
                    System.out.println(Thread.currentThread().getName() + "结束买票,剩余票数" + num);
                    return;
                }
            }
        }
/*
//        这个方法演示正常卖票线程执行
        @Override
        public void run() {
            while (true) {
                synchronized (num) {
                    System.out.println(Thread.currentThread().getName() + "开始卖票,剩余票数:" + num);
                    num--;
                    if (num <= 0) return;
                }
            }
        }
    */
    }

}
